package com.example.finalwork;

import static java.util.ResourceBundle.getBundle;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

public class DetailPage extends AppCompatActivity {
private ItemsDomain object;
private ImageView backBtn,itemImg;
private TextView titleTxt,descriptionTxt,ratingTxt;
private RatingBar ratingBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_detail_page);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        getBundles();
        initView();
        setVariable();
    }

    private void setVariable() {
        backBtn.setOnClickListener(v -> finish());

        int drawableResourseId = getResources().getIdentifier(object.getImgPath(),"drawable",DetailPage.this.getPackageName());
        Glide.with(DetailPage.this)
                .load(drawableResourseId)
                .into(itemImg);

        titleTxt.setText(object.getTitle());
        descriptionTxt.setText(object.getDescription());
        ratingTxt.setText("(" + object.getRate()+")");
        ratingBar.setRating((float) object.getRate());

    }

    private void initView() {
        backBtn = findViewById(R.id.backBtn);
        itemImg = findViewById(R.id.img);
        titleTxt = findViewById(R.id.titleTxt);
        descriptionTxt = findViewById(R.id.descriptionTxt);
        ratingBar = findViewById(R.id.ratingBar);
        ratingTxt = findViewById(R.id.ratingTxt);
    }

    private void getBundles() {
        object = (ItemsDomain) getIntent().getSerializableExtra("object");
    }
}